package com.cy.pj.sys.web.controller;

import com.cy.pj.sys.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysNotice;
import com.cy.pj.sys.service.SysNoticeService;
import com.cy.pj.sys.web.pojo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/notice/")
@RestController
public class SysNoticeController {
    @Autowired
    private SysNoticeService sysNoticeService;
    //请求url :http://localhost/notice/
    @GetMapping
    public JsonResult doFindNotices(
            SysNotice notice,Integer pageCurrent,Integer pageSize) {
        //启动分页查询
        //lambda表达式简化构建匿名内部类对象的过程
//        return new JsonResult (
//                PageHelper.startPage(1,3)
//                .doSelectPageInfo(()-> sysNoticeService.findNotices(notice)));
        return new JsonResult(PageUtil.startPage().doSelectPageInfo(()->
        sysNoticeService.findNotices(notice)));
    }

    @PostMapping
    public JsonResult doSaveNotice(@RequestBody SysNotice notice){
       sysNoticeService.saveNotice(notice);

        return new JsonResult("save ok");
    }

    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Long id){
        return  new JsonResult(sysNoticeService.findById(id));
    }

    @PutMapping
    public  JsonResult doUpdateNotice(@RequestBody SysNotice notice){
        sysNoticeService.updateNotice(notice);
        return new JsonResult("update ok");
    }

    @DeleteMapping("{ids}")
    public JsonResult doDeleteById(@PathVariable Long... ids){
        sysNoticeService.deleteById(ids);
        return new JsonResult("delete ok");

    }
    /**
     * Lambda表达式简化构造匿名内部类对象的过程
     * list.forEach(integer->system.out.println(integer));
     */

}

